import request from '@/utils/request'
import { AxiosPromise } from 'axios'

// apiUrl
const api = {
	create: '/v1/process/create', // 新增创建流程
	delete: '/v1/process/delete', // 删除流程
	listCategory: '/v1/process/list-category', // 流程分类定义列表列表
	clone: '/v1/process/clone', // 复制流程
	updateProcessState: '/v1/process/update-state', // 更新流程状态
	detailProcess: '/v1/process/get', // 流程详情
	launchProcessList: '/v1/process/list-launch', // 发起审批流程列表
	releaseProcess: '/v1/process/release', // 发布流程
	processListNodeMap: '/v1/process/list-node-map', // 根据 id 获取节点 map 列表
	processNodeModel: '/v1/process/node-model', // 根据 id 获取模型
	processLaunch: '/v1/process/launch', // 发起流程
	childProcessTop10: '/v1/process/list-child-top10', // 查询满足条件的前10条子流程列表
	pageHistoryList: '/v1/process/page-history', // 历史分页列表
	checkoutHistory: '/v1/process/checkout', // 根据Id签出历史流程
	businessProcess: '/v1/process/business' // 根据Key查询业务流程信息
}

function progressCreateApi(data: any): AxiosPromise {
	return request({
		url: api.create,
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function progressDeleteApi(data: any): AxiosPromise {
	return request({
		url: api.delete + '?id=' + data.id,
		method: 'post',
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}
function progressListCategoryApi(data: any): AxiosPromise {
	return request({
		url: api.listCategory,
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function launchProcessListApi(data: any): AxiosPromise {
	return request({
		url: api.launchProcessList,
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function releaseProcessApi(data: any): AxiosPromise {
	return request({
		url: `${api.releaseProcess}?id=${data.id}`,
		method: 'post'
	})
}

function processListNodeMapApi(id: string): AxiosPromise {
	return request({
		url: `${api.processListNodeMap}?id=${id}`,
		method: 'post'
	})
}
// 有问题 不再使用
function processNodeModelApi(id: string): AxiosPromise {
	return request({
		url: `${api.processNodeModel}?id=${id}`,
		method: 'post',
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function processLaunchApi(data): AxiosPromise {
	return request({
		url: api.processLaunch,
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function progressCloneApi(data: any): AxiosPromise {
	return request({
		url: api.clone + '?id=' + data.id,
		method: 'get',
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}
function processUpdateStateApi(data: any): AxiosPromise {
	return request({
		url: `${api.updateProcessState}-${data.id}` + '?state=' + data.state,
		method: 'post',
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function childProcessTop10Api(data: any): AxiosPromise {
	return request({
		url: `${api.childProcessTop10}?keyword=${data.keyword}`,
		method: 'post',
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function processDetailApi(id: any): AxiosPromise {
	return request({
		url: `${api.detailProcess}?id=${id}`,
		method: 'get'
	})
}

// pageHistoryList: '/v1/process/page-history', // 历史分页列表
// checkoutHistory: '/v1/process/checkout' // 根据Id签出历史流程
//{
//   "page": 0,
//   "pageSize": 0,
//   "data": {
//     "processId": 0,
//     "processName": "string"
//   }
// }
function pageHistoryListApi(data: any): AxiosPromise {
	return request({
		url: api.pageHistoryList,
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function checkoutHistoryApi(id: any): AxiosPromise {
	return request({
		url: `${api.checkoutHistory}?id=${id}`,
		method: 'post',
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

export function progressBusinessApi(): AxiosPromise {
	return request({
		url: api.businessProcess + '?key=purchaseOrder',
		method: 'get',
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

export default {
	progressCreateApi,
	progressDeleteApi,
	progressListCategoryApi,
	processListNodeMapApi,
	processNodeModelApi,
	processLaunchApi,
	progressCloneApi,
	processUpdateStateApi,
	processDetailApi,
	launchProcessListApi,
	releaseProcessApi,
	childProcessTop10Api,
	pageHistoryListApi,
	checkoutHistoryApi,
	progressBusinessApi
}
